/* $Id$ */
package org.crazydays.gameplan.db;


import java.util.Set;

import org.junit.*;
import static org.junit.Assert.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.map.IGameMap;

/**
 * Database
 */
public class DatabaseUnitTest
{
    /**
     * Test setName(String).
     */
    @Test
    public void testSetName()
    {
        // setup
        Database database = new Database();

        // test
        database.setName("aname");

        // verify
        assertEquals("database.name", "aname", database.name);
    }

    /**
     * Test getName().
     */
    @Test
    public void testGetName()
    {
        // setup
        Database database = new Database();

        // test
        database.setName("aname");

        // verify
        assertEquals("database.name", "aname", database.getName());
    }

    /**
     * Test getGameMaps().
     */
    @Test(expected = UnsupportedOperationException.class)
    public void testUnmodifiableGetMaps()
    {
        // mock
        IGameMap map = createMock(IGameMap.class);

        // replay
        replay(map);

        // setup
        Database database = new Database();
        Set<IGameMap> maps = database.getGameMaps();

        // test
        maps.add(map);
    }

    /**
     * Test addGameMaps().
     */
    @Test
    public void testAddGameMaps()
    {
        // mock
        IGameMap map = createMock(IGameMap.class);

        // replay
        replay(map);

        // setup
        Database database = new Database();

        // test
        database.addGameMap(map);

        // verify
        verify(map);

        assertEquals("maps", map, database.gameMaps.toArray()[0]);
    }
}
